package com.wedu.util;
//工具类

import java.io.*;
import java.util.*;

public class TSUtility {
    private static Scanner scanner = new Scanner(System.in);

    public static char readMenuSelection() {
        char c;
        for (; ; ) {
            String str = readKeyBoard(1, false);
            c = str.charAt(0);
            if (c != '1' && c != '2' &&
                    c != '3' && c != '4') {
                System.out.print("选择错误，请重新输入：");
            } else break;
        }
        return c;
    }
    public static char readMenuSelection2() {
        char c;
        for (; ; ) {
            String str = readKeyBoard(1, false);
            c = str.charAt(0);
            if (c < '1' || c > '9') {
                System.out.print("选择错误，请重新输入：");
            } else break;
        }
        return c;
    }
    public static char readMenuSelection1() {
        char c;
        for (; ; ) {
            String str = readKeyBoard(1, false);
            c = str.charAt(0);
            if (c != '1' && c != '2'&&c!='3') {
                System.out.print("选择错误，请重新输入：");
            } else break;
        }
        return c;
    }

    public static char readMenuSelection3() {
        char c;
        for (; ; ) {
            String str = readKeyBoard(1, false);
            c = str.charAt(0);
            if (c != '1' && c != '2') {
                System.out.print("选择错误，请重新输入：");
            } else break;
        }
        return c;
    }
    public static char readMenuSelectionPro() {
        char c;
        for (; ; ) {
            String str = readKeyBoard(1, false);
            c = str.charAt(0);
            if (c != '1' && c != '2' &&
                    c != '3' && c != '4' && c != '5'&&c!='6'&&c!='7') {
                System.out.print("选择错误，请重新输入：");
            } else break;
        }
        return c;
    }
    public static char readMenuSelectionPro1() {
        char c;
        for (; ; ) {
            String str = readKeyBoard(1, false);
            c = str.charAt(0);
            if (c != '1' && c != '2' &&
                    c != '3' && c != '4' && c != '5') {
                System.out.print("选择错误，请重新输入：");
            } else break;
        }
        return c;
    }
    public static char readMenuSelectionPro3() {
        char c;
        for (; ; ) {
            String str = readKeyBoard(1, false);
            c = str.charAt(0);
            if (c != '1' && c != '2' &&
                    c != '3' && c != '4' && c != '5'&&c!='6') {
                System.out.print("选择错误，请重新输入：");
            } else break;
        }
        return c;
    }

    public static void readReturn() {
        System.out.print("按回车键继续...");
        readKeyBoard(100, true);
    }


    /**
     从键盘读取一个长度不超过2位的整数，并将其作为方法的返回值。
     如果用户不输入字符而直接回车，方法将以defaultValue 作为返回值。
     */

    public static int did(){
        Scanner sc = new Scanner(System.in);
        for (;;) {
            System.out.print("请输入职位编号：");
            try {
                String str=sc.next();
                return Integer.parseInt(str);
            } catch (Exception e) {
                System.out.println("请正确输入申请兼职编号！");
            }
        }
    }

    public static char readConfirmSelection() {
        char c;
        for (; ; ) {
            String str = readKeyBoard(1, false).toUpperCase();
            c = str.charAt(0);
            if (c == 'Y' || c == 'N') {
                break;
            } else {
                System.out.print("选择错误，请重新输入：");
            }
        }
        return c;
    }
    public static char readConfirmSelection1() {
        char c;
        for (; ; ) {
            String str = readKeyBoard(1, false).toUpperCase();
            c = str.charAt(0);
            if (c == 'A' || c == 'B'||c=='C') {
                break;
            } else {
                System.out.print("选择错误，请重新输入：");
            }
        }
        return c;
    }
    /**
     从键盘读取一个长度不超过limit的字符串，并将其作为方法的返回值。
     如果用户不输入字符而直接回车，方法将以defaultValue 作为返回值。
     */
    public static String readString(int limit, String defaultValue) {
        String str = readKeyBoard(limit, true);
        return str.equals("")? defaultValue : str;
    }

    public static String readKeyBoard(int limit, boolean blankReturn) {
        String line = "";

        while (scanner.hasNextLine()) {
            line = scanner.nextLine();
            if (line.length() == 0) {
                if (blankReturn) return line;
                else continue;
            }

            if (line.length() > limit) {
                System.out.print("输入长度（不大于" + limit + "）错误，请重新输入：");
                continue;
            }
            break;
        }

        return line;
    }

    public static void loadSpecialEffects()  {
        try {
            System.out.println("请稍等：");
            for (int i1 = 1; i1 <= 100; i1++) {
                System.out.print("加载中：" + i1 + "%");
                Thread.sleep(new Random().nextInt(25) + 1);
                if (i1 == 100) {
                    Thread.sleep(50);
                }
                System.out.print("\r");
            }
        }catch (Exception e){
            e.fillInStackTrace();
        }

    }

}
